import pathlib
import os
source_tree_path = os.path.expandvars(r"%LocalAppData%\\Atlassian\\SourceTree\\")
json_content = '''[
  {
    "$id": "1",
    "$type": "SourceTree.Api.Host.Identity.Model.IdentityAccount, SourceTree.Api.Host.Identity",
    "Authenticate": true,
    "HostInstance": {
      "$id": "2",
      "$type": "SourceTree.Host.Atlassianaccount.AtlassianAccountInstance, SourceTree.Host.AtlassianAccount",
      "Host": {
        "$id": "3",
        "$type": "SourceTree.Host.Atlassianaccount.AtlassianAccountHost, SourceTree.Host.AtlassianAccount",
        "Id": "atlassian account"
      },
      "BaseUrl": "https://id.atlassian.com/"
    },
    "Credentials": {
      "$id": "4",
      "$type": "SourceTree.Model.BasicAuthCredentials, SourceTree.Api.Account",
      "Username": "",
      "Email": null
    },
    "IsDefault": false
  }
]
'''
json_file_name = "accounts.json"

def do_patch(source_tree_dir, file_name, file_content):
    file_path = pathlib.Path(source_tree_dir)/file_name
    print("try patch: ", file_path)
    if file_path.exists():
        print("already patched!!!!")
        return

    with file_path.open("w", encoding='utf-8') as f:
        f.write(file_content)

    print("patched !!!!!")

if __name__ == "__main__":
    do_patch(source_tree_path, json_file_name, json_content)
